package com.example.dc.Service.Impl;


import com.example.dc.domain.Chat;
import com.example.dc.mapper.UserMapper;
import com.example.dc.Service.UserService;
import com.example.dc.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findPassword(String account) {
        return userMapper.findPassword(account);
    }

    @Override
    public boolean codeIsRight(String account, String code) {
        return userMapper.codeIsRight(account,code);
    }

    @Override
    public User getUserInfo(Integer id) {
        return userMapper.getUserInfoByUserId(id);
    }

    @Override
    public List<User> getTeamAndUser(Integer teamId){
        return userMapper.getTeamAndUser(teamId);
    }

    @Override
    public Integer register(String account, String password,Character type){
        userMapper.insertUserInfo("默认_用户");
        Integer id=userMapper.getMax();
        userMapper.register(id,account,password,type);
        return id;
    }

    public Integer findUser(String phone){
        return userMapper.findUser(phone);
    }

    @Override
    public void updateUserAuth(Integer userId,String name, Integer age, Character sex) {
        userMapper.updateUserAuth(userId,name,age,sex);
    }

    @Override
    public Boolean isFirst(Integer userId){
        return userMapper.isFirst(userId);
    }

    @Override
    public void updateRegistTime(Integer userId) {
        userMapper.updateRegistTime(userId);
    }

    @Override
    public void updateUserInfo(String nickname, String avatar, String intro, Integer userId) {
        userMapper.updateUserInfo(nickname, avatar, intro, userId);
    }

    @Override
    public void requestCode(String phone,String  code,Character type){
         userMapper.requestCode(phone, code,type);
    }

    @Override
    public void editUser(User user) {
        Integer userId=user.getId();
        String nickname=user.getNickname();
        String phone=user.getPhone();
        Character sex=user.getSex();
        String birthday=user.getBirthday();
        String location=user.getLocation();
        String industry=user.getIndustry();
        String like=user.getLike();
        String intro=user.getIntro();
        String avatar=user.getAvatar();
        userMapper.editUserAuth(userId,phone,sex,birthday,location,industry,like);
        userMapper.editUserInfo(userId,nickname,avatar,intro);
    }

    @Override
    public User getUserInfoByAccount(String account) {
        return userMapper.getUserInfoByAccount(account);
    }

    @Override
    public void insertLoginHistory(String account,String password, String address, Character type, Character status) {
        userMapper.insertLoginHistory(account,password,address,type,status);
    }
}
